var socket1=null
var socket2=null
var socket3=null
var socket4=null
var socket5=null
var socket6=null
function establishCommunication1(){
    connectsocket1()
    console.log(socket1.readyState)
    setInterval(() => {
        if (socket1.readyState === WebSocket.CLOSED) {
            socket1.onopen = () => {
                console.log('socket1 connected');
                // this.startHeartbeat();
            };
        }
    }, 10000); // 每10秒判断一次socket1连接状态，未连接进行重连
}
function connectsocket1(){
    socket1 = new WebSocket('ws://10.11.82.18:8091/myapp/ws?page=obtainDeviceStatus'); // 获取设备实时状态数据URL
    socket1.onopen = () => {
        console.log('socket1 connected');
        // this.startHeartbeat();
    };
    socket1.onerror = (error) => {
        console.error('socket1 error:', error);
    }
}
function establishCommunication2(){
    connectsocket2()
    console.log(socket2.readyState)
    setInterval(() => {
        if (socket2.readyState === WebSocket.CLOSED) {
            socket2.onopen = () => {
                console.log('socket2 connected');
                // this.startHeartbeat();
            };
        }
    }, 10000); // 每10秒判断一次socket2连接状态，未连接进行重连
}
function connectsocket2(){
    socket2 = new WebSocket('ws://10.11.82.18:8091/myapp/ws?page=obtainAlarmData'); // 获取实时报警数据URL
    socket2.onopen = () => {
        console.log('socket2 connected');
        // this.startHeartbeat();
    };
    socket2.onerror = (error) => {
        console.error('socket2 error:', error);
    }
}
function establishCommunication3(){
    connectsocket3()
    console.log(socket3.readyState)
    setInterval(() => {
        if (socket3.readyState === WebSocket.CLOSED) {
            socket3.onopen = () => {
                console.log('socket3 connected');
                // this.startHeartbeat();
            };
        }
    }, 10000); // 每10秒判断一次socket3连接状态，未连接进行重连
}
function connectsocket3(){
    socket3 = new WebSocket('ws://10.11.82.18:8091/myapp/ws?page=obtainNoGoodData'); // 获取NG实时数据URL
    socket3.onopen = () => {
        console.log('socket3 connected');
        // this.startHeartbeat();
    };
    socket3.onerror = (error) => {
        console.error('socket3 error:', error);
    }
}
function establishCommunication4(){
    connectsocket4()
    console.log(socket4.readyState)
    setInterval(() => {
        if (socket4.readyState === WebSocket.CLOSED) {
            socket4.onopen = () => {
                console.log('socket4 connected');
                // this.startHeartbeat();
            };
        }
    }, 10000); // 每10秒判断一次socket4连接状态，未连接进行重连
}
function connectsocket4(){
    socket4 = new WebSocket('ws://10.11.82.18:8091/myapp/ws?page=obtainHistoryStatus'); // 获取当班历史状态数据URL
    socket4.onopen = () => {
        console.log('socket4 connected');
        // this.startHeartbeat();
    };
    socket4.onerror = (error) => {
        console.error('socket4 error:', error);
    }
}
function establishCommunication5(){
    connectsocket5()
    console.log(socket5.readyState)
    setInterval(() => {
        if (socket5.readyState === WebSocket.CLOSED) {
            socket5.onopen = () => {
                console.log('socket5 connected');
                // this.startHeartbeat();
            };
        }
    }, 10000); // 每10秒判断一次socket5连接状态，未连接进行重连
}
function connectsocket5(){
    socket5 = new WebSocket('ws://10.11.82.18:8091/myapp/ws?page=obtainHourData'); // 获取当班小时别生产数据URL
    socket5.onopen = () => {
        console.log('socket5 connected');
        // this.startHeartbeat();
    };
    socket5.onerror = (error) => {
        console.error('socket5 error:', error);
    }
}
function establishCommunication6(){
    connectsocket6()
    console.log(socket6.readyState)
    setInterval(() => {
        if (socket6.readyState === WebSocket.CLOSED) {
            socket6.onopen = () => {
                console.log('socket6 connected');
                // this.startHeartbeat();
            };
        }
    }, 10000); // 每10秒判断一次socket6连接状态，未连接进行重连
}
function connectsocket6(){
    socket6 = new WebSocket('ws://10.11.82.18:8091/myapp/ws?page=obtainDayData'); // 获取近7天天别生产数据URL
    socket6.onopen = () => {
        console.log('socket6 connected');
        // this.startHeartbeat();
    };
    socket6.onerror = (error) => {
        console.error('socket6 error:', error);
    }
}
export {socket1,establishCommunication1,socket2,establishCommunication2,socket3,establishCommunication3,
    socket4,establishCommunication4,socket5,establishCommunication5,socket6,establishCommunication6}